//
//  HSWebController.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/9/29.
//  Copyright © 2016年 赖虹宇. All rights reserved.
//

import UIKit
import SnapKit

class HSWebController: UIViewController,UIWebViewDelegate {
    var urlStr = String()
    lazy var webView:UIWebView = UIWebView(frame: CGRect(x: 0, y: 64, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
    lazy var activity: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
      
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        setupTopUI()
        
        //设置活动指示器
        activity.center = view.center
        webView.addSubview(activity)
        //网页设置
       let url = URL(string: urlStr) 
        let request = URLRequest(url: url!)
        webView.loadRequest(request)
        webView.delegate = self
        
//         UIApplication.shared.open(url)
        
        
      

    }
    //设置顶部UI
    func setupTopUI(){
        //模拟一个假导航栏
        let navVc = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 64))
        navVc.backgroundColor = UIColor().colorWithHex(0x009ee7)
        view.addSubview(navVc)
        //返回按钮
        let back = UIButton(frame: CGRect(x: 8, y: 16, width: 70, height: 48))
        back.setImage(UIImage(named:"back"), for: .normal)
        back.addTarget(self, action: #selector(backBtnClicked), for: .touchUpInside)
        navVc.addSubview(back)
        //文字
        let label = UILabel(frame: CGRect(x: 60, y: 16, width: 150, height: 48))
        label.text = "关于我们"
        label.textColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        label.font = UIFont.systemFont(ofSize: 20)
        
        navVc.addSubview(label)
          view.addSubview(webView)

    }
    //活动指示器代理方法
    func webViewDidStartLoad(_ webView: UIWebView) {
        activity.startAnimating()
    }
    func webViewDidFinishLoad(_ webView: UIWebView) {
        activity.stopAnimating()
    }
    
    
    
    //返回按钮监听方法
    func backBtnClicked(){
        dismiss(animated: true, completion: nil)
    }
}
